package com.example.myviewmodelframe.base.activity

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView


/**
 * @author tgw
 * @date 2022/7/6
 * @describe
 */
class BaseRecyclerViewHolder<VB : ViewDataBinding>(val mBind: VB) :
    RecyclerView.ViewHolder(mBind.root) {

}

abstract class BaseRecyclerViewAdapter<VB : ViewDataBinding> :
    RecyclerView.Adapter<BaseRecyclerViewHolder<VB>>() {


    abstract fun getLayoutInflateId(): Int

    abstract fun bindData(itemBind: VB, position: Int)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseRecyclerViewHolder<VB> {
        var mBind: VB = DataBindingUtil.inflate(
            LayoutInflater.from(parent.context),
            getLayoutInflateId(),
            parent,
            false
        )
        return BaseRecyclerViewHolder(mBind)
    }

    override fun onBindViewHolder(holder: BaseRecyclerViewHolder<VB>, position: Int) {
        bindData(holder.mBind, position)
    }


}

//class MyTestAdapter : BaseRecyclerViewAdapter<ActivityViewpager2ListadapterItemLayoutBinding>() {
//
//    private var mList: List<String> = ArrayList()
//
//
//    override fun getLayoutInflateId(): Int {
//        return R.layout.activity_viewpager2_listadapter_item_layout;
//    }
//
//    var colors = arrayOf("#CCFF99", "#41F1E5", "#8D41F1", "#FF99CC")
//    override fun bindData(
//        mBind: ActivityViewpager2ListadapterItemLayoutBinding,
//        position: Int
//    ) {
//
//        mBind.tv.text = "我是viewpager2- -MyTestAdapter的布局-----：${mList[position]}"
//        mBind.tv.setBackgroundColor(Color.parseColor(colors[position % 4]))
//    }
//
//
//    fun setList(list: List<String>) {
//        mList = list
//    }
//
//    override fun getItemCount(): Int {
//        return mList.size
//    }
//
//}